package org.kim.core;

import org.kim.pojo.Account;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class Session {

    private static final Set<Account> sessionSet = Collections.synchronizedSet(new HashSet<>());

    public static void set(Account account) {
        sessionSet.add(account);
    }

    public static boolean exists() {
        return !sessionSet.isEmpty();
    }

    public static List<Account> getAll() {
        List<Account> list = sessionSet.stream().collect(Collectors.toList());
        return list;
    }

    public static Account getAny() {
        Optional<Account> optional = sessionSet.stream().findFirst();
        return optional.isPresent() ? optional.get() : null;
    }


    public static void delete(Account account) {
        sessionSet.remove(account);
    }

    public static void clear() {
        sessionSet.clear();
    }


}
